package clientGUI;

import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JButton;

import subscriberPanels.ExtendBorrowPanel;
import subscriberPanels.OrderBookPanel;
import subscriberPanels.UpdateDetailsPanel;
import subscriberPanels.ViewMyReaderCardPanel;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.ImageIcon;

/**
 * @author Shay
 *	Creating subscriber GUI
 */
public class SubscriberGUI extends JPanel 
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final static SubscriberGUI lGUI=null;
	private JButton canceledButton;
	public JButton btnViewMyReaderCard;
	public JButton btnExtendBorrow;
	private JButton btnOrderBook;
	public JButton btnLogout;
	public JButton btnUpdateDetails;
	public static SubscriberGUI getInstance()
	{
		if(lGUI==null)
			return new SubscriberGUI();
		return lGUI;
	}
	
	private SubscriberGUI() 
	{
		canceledButton=new JButton();
		setBorder(new LineBorder(new Color(0, 0, 0), 3, true));
		setPreferredSize(new Dimension(219, 547));
		setLayout(null);
		
		btnViewMyReaderCard = new JButton("View My Reader Card");
		btnViewMyReaderCard.setFont(new Font("Tahoma", Font.PLAIN, 11));
		btnViewMyReaderCard.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ViewMyReaderCardPanel p=new ViewMyReaderCardPanel();
				MainGUI.middlePanelChange(p);
				canceledButton.setEnabled(true);
				canceledButton=btnViewMyReaderCard;
				canceledButton.setEnabled(false);
			}
		});	
		
		btnViewMyReaderCard.setBounds(10, 11, 199, 41);
		add(btnViewMyReaderCard);
		
		
		btnExtendBorrow = new JButton("Extend Borrow");
		btnExtendBorrow.setFont(new Font("Tahoma", Font.PLAIN, 11));
		btnExtendBorrow.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ExtendBorrowPanel p=new ExtendBorrowPanel();
				MainGUI.middlePanelChange(p);
				canceledButton.setEnabled(true);
				canceledButton=btnExtendBorrow;
				canceledButton.setEnabled(false);
			}
		});
		
		btnExtendBorrow.setBounds(10, 63, 199, 41);
		add(btnExtendBorrow);
		
		btnOrderBook = new JButton("Search");
		btnOrderBook.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				OrderBookPanel p = new OrderBookPanel();
				MainGUI.middlePanelChange(p);	
				canceledButton.setEnabled(true);
				canceledButton=btnOrderBook;
				canceledButton.setEnabled(false);
			}
		});
		btnOrderBook.setBounds(10, 115, 199, 41);
		add(btnOrderBook);
		
		btnUpdateDetails = new JButton("Update Details");
		btnUpdateDetails.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				UpdateDetailsPanel p= new UpdateDetailsPanel();
				MainGUI.middlePanelChange(p);	
				canceledButton.setEnabled(true);
				canceledButton=btnUpdateDetails;
				canceledButton.setEnabled(false);
			}
		});
		btnUpdateDetails.setBounds(10, 167, 199, 41);
		add(btnUpdateDetails);
		
		btnLogout = new JButton("Logout");
		btnLogout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String x[]=new String[1];
				x[0]="Logoff";
				MainGUI.OBLClient.handleMessageFromClient(x);
			}
		});
		btnLogout.setBounds(10, 482, 199, 41);
		add(btnLogout);
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon("images/book3.jpg"));
		label.setBounds(3, 3, 215, 540);
		add(label);
		
	}
	public String toString()
	{
		return "SubscriberGUI";
	}
}
